package tjs.study.notes.dotest.mongo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import tjs.study.notes.dotest.TjsStudyNotesApplication;
import tjs.study.notes.dotest.mongo.service.UserMongoMapper;
import tjs.study.notes.dotest.mongo.service.UserMongoService;

/**
 * Created by Nicky.Tang on 2021/12/9 9:32 下午
 *
 * @since 02.12.10
 */
@EnableTransactionManagement
@SpringBootApplication
public class ClientA implements CommandLineRunner {
    /**
     * 提交事务：{@link org.springframework.data.mongodb.MongoTransactionManager#doCommit(org.springframework.transaction.support.DefaultTransactionStatus)}
     * 回滚事务：{@link org.springframework.data.mongodb.MongoTransactionManager#doRollback(org.springframework.transaction.support.DefaultTransactionStatus)}
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(TjsStudyNotesApplication.class, args);
    }

    @Autowired
    private UserMongoService userMongoService;
    @Autowired
    private UserMongoMapper userMongoMapper;

    @Override
    public void run(String... args) throws Exception {
        //userMongoService.test脏读();
//        userMongoService.test不可重复读();
        userMongoService.test幻读();
//        userMongoMapper.resetName("61b4742e568141738d955fc5","test aop");
    }

    public static void sleep(Long millis) {
        if (millis == null) {
            return;
        }
        try {
            Thread.currentThread().sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
